from django.shortcuts import render,HttpResponse
#from django import HttpResponse
from django.http import JsonResponse
import json


from .models import Platform, Group

# Create your views here.
def get_group(request, platform_id):    
    # 根据传递的项目的id 查找数据库中该省的群组
    result = [] 
    platforms = platform_id.split(","); 
    for p in platforms:
        groups = Group.objects.filter(platform_id=p)          
        for i in groups:        
            # 对应的id和群组名称组成一个字典        
            result.append({'id':i.id, 'name':i.name})    
            # 返回json数据    
    return HttpResponse(json.dumps(result), content_type="application/json")